<template>
  <div class="body">
    <div class="carousel">
      <!-- 左侧控制按钮 -->
      <div class="carousel-control-button left">
        <input type="radio" name="carousel-control-input" />
      </div>
      <!-- 右侧控制按钮，默认选中 -->
      <div class="carousel-control-button right">
        <input type="radio" name="carousel-control-input" checked />
      </div>

      <!-- 轮播方向 -->
      <div class="carousel-rotation-direction">
        <!-- 轮播项容器 -->
        <ul
          class="carousel-item-wrapper"
          :style="{ '--_num-elements': images.length }"
        >
          <!-- 遍历图片数组，生成轮播项 -->
          <template v-for="(item, index) in images">
            <li
              class="carousel-item"
              :style="{ '--_index': index, '--_image-url': `url(${item})` }"
            >
              <a href="https://blog.taoqilin.cn/" target="_blank"
                >Architecture Example {{ index + 1 }}</a
              >
            </li>
          </template>
          <!-- 轮播项空容器 -->
          <li class="carousel-ground"></li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
// 导入图片
import image1 from "/@/assets/images/rotateAlbum/1.jpg";
import image2 from "/@/assets/images/rotateAlbum/2.jpg";
import image3 from "/@/assets/images/rotateAlbum/3.jpg";
import image4 from "/@/assets/images/rotateAlbum/4.jpg";
import image5 from "/@/assets/images/rotateAlbum/5.jpg";
import image6 from "/@/assets/images/rotateAlbum/6.jpg";
import image7 from "/@/assets/images/rotateAlbum/7.jpg";
import image8 from "/@/assets/images/rotateAlbum/8.jpg";
import image9 from "/@/assets/images/rotateAlbum/9.jpg";
import image10 from "/@/assets/images/rotateAlbum/10.jpg";
import image11 from "/@/assets/images/rotateAlbum/11.jpg";
import image12 from "/@/assets/images/rotateAlbum/12.jpg";

// 定义图片数组
const images = [
  image1,
  image2,
  image3,
  image4,
  image5,
  image6,
  image7,
  image8,
  image9,
  image10,
  image11,
  image12,
];
</script>

<style lang="scss" scoped>
/*
vars
*/
.body {
  --carousel-transition-duration: 250ms;
  /* 轮播过渡动画持续时间 */
  --carousel-transition-ease: ease-out;
  /* 轮播过渡动画缓动函数 */
  --carousel-bg-color-rgb: 0, 0, 0;
  /* 轮播背景颜色 */
  --carousel-shadow-color-rgb: 128, 128, 128;
  /* 轮播阴影颜色 */
  --carousel-item-width: 11.5rem;
  /* 轮播项宽度 */
  --carousel-item-height: 17.5rem;
  /* 轮播项高度 */
  --carousel-item-hover-effect: 1.075;
  /* 轮播项悬停效果 */
  --carousel-item-reflection-blur: 0.25rem;
  /* 轮播项反射模糊度 */
  --carousel-item-empty-color-rgb: 255, 255, 255;
  /* 轮播项空颜色 */
  --carousel-item-glow-color-rgb: 255, 255, 255;
  /* 轮播项光晕颜色 */
  --carousel-item-glow-size: 5rem;
  /* 轮播项光晕大小 */
  --carousel-diameter: 50rem;
  /* 轮播直径 */
  --carousel-3d-perspective: 1000px;
  /* 轮播3D透视 */
  --carousel-3d-perspective-origin: 50% 20%;
  /* 轮播3D透视原点 */
  --carousel-control-button-width: 1.25rem;
  /* 轮播控制按钮宽度 */
  --carousel-control-button-height: 4rem;
  /* 轮播控制按钮高度 */
  --carousel-control-color-rgb: 255, 255, 255;
  /* 轮播控制按钮颜色 */
  --carousel-animation-duration: 25s;
  /* 轮播动画持续时间 */
  --carousel-animation-play-state: running;
  /* 轮播动画播放状态 */
  --carousel-direction-animation-play-state: paused;
  /* 轮播方向动画播放状态 */
}

/*
global
*/
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  border: 0;
}

*:focus {
  outline: none;
}

a {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background-color: rgb(var(--carousel-bg-color-rgb));
  overflow: hidden;
}

/*
carousel
*/
.carousel {
  --_diameter: var(--carousel-diameter);
  --_radius: calc(var(--_diameter) / 2);
  --_item-width: var(--carousel-item-width);
  --_item-height: var(--carousel-item-height);
  perspective: var(--carousel-3d-perspective);
  perspective-origin: var(--carousel-3d-perspective-origin);
  width: var(--_diameter);
  height: var(--_diameter);
}

@media only screen and (max-width: 48rem) {
  .carousel {
    --_diameter: calc(var(--carousel-diameter) * 0.75);
    --_item-width: calc(var(--carousel-item-width) * 0.75);
    --_item-height: calc(var(--carousel-item-height) * 0.75);
  }
}

@media only screen and (max-width: 32rem) {
  .carousel {
    --_diameter: calc(var(--carousel-diameter) * 0.6);
    --_item-width: calc(var(--carousel-item-width) * 0.6);
    --_item-height: calc(var(--carousel-item-height) * 0.6);
  }
}

@media only screen and (max-width: 16rem) {
  .carousel {
    --_diameter: calc(var(--carousel-diameter) * 0.25);
    --_item-width: calc(var(--carousel-item-width) * 0.25);
    --_item-height: calc(var(--carousel-item-height) * 0.25);
  }
}

.carousel .carousel-control-button {
  --_width: var(--carousel-control-button-width);
  --_height: var(--carousel-control-button-height);
  z-index: 1;
  width: var(--_width);
  height: var(--_height);
  background-color: rgb(var(--carousel-control-color-rgb));
  opacity: 0.2;
  transition: opacity var(--carousel-transition-duration)
    var(--carousel-transition-ease);
  position: absolute;
}

.carousel .carousel-control-button:hover {
  opacity: 0.4;
}

.carousel .carousel-control-button:has(input:checked) {
  opacity: 0.8;
}

.carousel .carousel-control-button input {
  -webkit-appearance: none;
  appearance: none;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.carousel .carousel-control-button.left {
  clip-path: polygon(0% 50%, 100% 0%, 100% 100%);
  top: calc(var(--_radius) - var(--_height) / 2);
  left: 0;
}

.carousel:has(.carousel-control-button.left input:checked) {
  --carousel-direction-animation-play-state: running;
}

.carousel .carousel-control-button.right {
  clip-path: polygon(0% 0%, 100% 50%, 0% 100%);
  top: calc(var(--_radius) - var(--_height) / 2);
  right: 0;
}

.carousel:has(.carousel-control-button.right input:checked) {
  --carousel-direction-animation-play-state: paused;
}

.carousel .carousel-rotation-direction {
  --_direction-animation-play-state: var(
    --carousel-direction-animation-play-state
  );
  --_z: calc(var(--_radius) * -1);
  transform: translateZ(var(--_z));
  transform-style: preserve-3d;
  animation: carousel-rotation-reverse
    calc(var(--carousel-animation-duration) / 2) reverse linear infinite
    var(--_direction-animation-play-state);
  transition: all var(--carousel-transition-duration)
    var(--carousel-transition-ease);
}

@keyframes carousel-rotation-reverse {
  from {
    transform: translateZ(var(--_z)) rotateY(0deg);
  }

  to {
    transform: translateZ(var(--_z)) rotateY(360deg);
  }
}

@keyframes carousel-rotation-normal {
  from {
    transform: rotateY(0deg);
  }

  to {
    transform: rotateY(360deg);
  }
}

.carousel .carousel-item-wrapper {
  transform-style: inherit;
  width: inherit;
  height: inherit;
  list-style-type: none;
  position: relative;
  animation: carousel-rotation-normal var(--carousel-animation-duration) normal
    linear infinite var(--carousel-animation-play-state);
  transition: all var(--carousel-transition-duration)
    var(--carousel-transition-ease);
}

.carousel .carousel-rotation-direction:has(.carousel-item:hover) {
  --carousel-animation-play-state: paused;
  --_direction-animation-play-state: paused;
}

.carousel .carousel-item {
  --_width: var(--_item-width);
  --_height: var(--_item-height);
  --_rotation: calc(360 / var(--_num-elements) * var(--_index) * 1deg);
  left: calc(var(--_radius) - var(--_item-width) / 2);
  top: calc(var(--_radius) - var(--_item-height) / 2);
  transform: rotateY(var(--_rotation)) translateZ(var(--_radius));
  transform-style: inherit;
  width: var(--_width);
  height: var(--_height);
  transition: all var(--carousel-transition-duration)
    var(--carousel-transition-ease);
  box-shadow: 0 0 var(--carousel-item-glow-size) transparent;
  position: absolute;
}

.carousel .carousel-item:hover {
  box-shadow: 0 0 var(--carousel-item-glow-size)
    rgb(var(--carousel-item-glow-color-rgb));
  transform: rotateY(var(--_rotation))
    translateZ(calc(var(--_radius) * var(--carousel-item-hover-effect)));
}

.carousel .carousel-item a {
  display: block;
  width: inherit;
  height: inherit;
  text-indent: -9999px;
  background-color: rgba(var(--carousel-item-empty-color-rgb), 0.5);
  background-image: var(--_image-url);
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  transition: filter var(--carousel-transition-duration)
    var(--carousel-transition-ease);
  filter: grayscale(100%);
}

.carousel .carousel-item:hover a {
  filter: grayscale(0%);
}

.carousel .carousel-item::before {
  /* 设置伪元素内容为空 */
  content: "";
  /* 设置伪元素宽度为继承 */
  width: inherit;
  /* 设置伪元素高度为继承 */
  height: inherit;
  /* 设置伪元素背景颜色为半透明的渐变颜色 */
  background-color: rgba(var(--carousel-item-empty-color-rgb), 0.5);
  /* 设置伪元素背景图片为线性渐变和图片 */
  background-image: linear-gradient(
      to top,
      rgba(var(--carousel-bg-color-rgb), 0.25) 0%,
      rgba(var(--carousel-bg-color-rgb), 1) 75%
    ),
    var(--_image-url);
  /* 设置伪元素背景图片不重复 */
  background-repeat: no-repeat;
  /* 设置伪元素背景图片居中显示 */
  background-position: center;
  /* 设置伪元素背景图片覆盖整个元素 */
  background-size: cover;
  /* 设置伪元素不响应鼠标事件 */
  pointer-events: none;
  /* 设置伪元素模糊和灰度效果 */
  filter: blur(var(--carousel-item-reflection-blur)) grayscale(100%);
  /* 设置伪元素过渡效果 */
  transition: filter var(--carousel-transition-duration)
    var(--carousel-transition-ease);
  /* 设置伪元素变换样式为继承 */
  transform-style: inherit;
  /* 设置伪元素变换原点为元素中心底部 */
  transform-origin: center bottom;
  /* 设置伪元素变换效果为旋转 */
  transform: rotateX(90deg) rotateZ(180deg) rotateY(180deg);
  /* 设置伪元素定位为绝对定位 */
  position: absolute;
  left: 0;
  top: 0;
}

.carousel .carousel-item:hover::before {
  filter: blur(var(--carousel-item-reflection-blur)) grayscale(0%);
}

.carousel .carousel-ground {
  --_width: var(--_diameter);
  --_height: var(--_diameter);
  --_rotation: 90deg;
  left: calc(var(--_radius) - var(--_width) / 2);
  top: calc(var(--_radius) - var(--_height) / 2);
  transform: rotateX(var(--_rotation))
    translateZ(calc(var(--_item-height) / -2));
  width: var(--_width);
  height: var(--_height);
  border-radius: 50%;
  background: radial-gradient(
    rgba(var(--carousel-shadow-color-rgb), 0.75) 15%,
    rgba(var(--carousel-bg-color-rgb), 0) 60%
  );
  opacity: 0.5;
  transition: opacity var(--carousel-transition-duration)
    var(--carousel-transition-ease);
  position: absolute;
}

.carousel .carousel-item-wrapper:has(.carousel-item:hover) .carousel-ground {
  opacity: 0.75;
}
</style>
